home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000034_icon-group-sender_Wed Mar 12 12:50:02 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h2CJmd603887
  4.     for icon-group-addresses; Wed, 12 Mar 2003 12:48:39 -0700 (MST)
  5. Message-Id: <200303121948.h2CJmd603887@baskerville.CS.Arizona.EDU>
  6. X-Authentication-Warning: weaver.tuc.noao.edu: swampler set sender to swampler@noao.edu using -f
  7. Subject: Re: Sorting lists
  8. From: Steve Wampler <swampler@noao.edu>
  9. To: rjhare@ed.ac.uk
  10. Cc: icon-group@cs.arizona.edu
  11. Date: 12 Mar 2003 09:34:29 -0700
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14.  
  15. On Wed, 2003-03-12 at 08:51, Steve Wampler wrote:
  16. > On Wed, 2003-03-12 at 07:21, rjhare@ed.ac.uk wrote:
  17. > > I don't have the book to hand and am sitting in an Icon-free zone at
  18. > > the moment. What do I get if I sort a list of lists like this:
  19. > > 
  20. > > [ [b,c], [a,d] ]
  21. > > 
  22. > > I hope I get:
  23. > > 
  24. > > [ [a,d], [b,c]]
  25. > > 
  26. > > but fear that I might get:
  27. > > 
  28. > > [ a, b, c, d]
  29. > > 
  30. > > Thanks.
  31. > > 
  32. > > Roger Hare
  33. > To make sure I understand, you have (say)
  34. >    a := [ ["b","c"], ["a","d"] ]
  35. > and want to know the result of sort(a), right?
  36. > The answer is that you won't get [ "a", "b", "c", "d" ],
  37. > but you probably will not get [ ["a","d"], ["b", "c"] ], either.
  38. > When sorting a list of structures (what you have), the
  39. > sorting order is by time of creation of those structures.
  40. > Icon won't look 'inside' those structures to see what they
  41. > contain.  So, since ["b","c"] was created before ["a","d"]
  42. > in the above example, I would expect the result of the
  43. > sort to be [ ["b","c"], ["a","d"] ].
  44.  
  45. A quick followup...
  46.  
  47. If you do have a list of lists of strings, you *can* use
  48. sortf(X,i) instead of sort() to sort by the first element in
  49. each of the sublists, so:
  50.  
  51.     b := sortf(a, 1)
  52.  
  53. would do what you want in the above example.
  54.  
  55. -- 
  56. Steve Wampler <swampler@noao.edu>
  57. National Solar Observatory
  58.